package com.bnz.servlet;

import com.alibaba.fastjson.JSON;
import com.bnz.pojo.Classes;
import com.bnz.service.ClassesService;
import com.bnz.service.impl.ClassesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private ClassesService classesService;
	@Override
	public void init() throws ServletException {
		classesService = new ClassesServiceImpl();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf8");
		//1. 查询得到所有班级列表
		List<Classes> classes = classesService.findAll();
		//2. 转换为json串
		String s = JSON.toJSONString(classes);
		//3. 输出
		resp.getWriter().println(s);
		//4. 刷新
		resp.getWriter().flush();
	}
}
